<template>
  <div class="singer" v-loading="!data.length">
    <indexList :data="data" @select="selectSinger"></indexList>
    <!-- <router-view :singer="selectedSinger"></router-view> -->
    <router-view v-slot="{Component}">
      <transition appear name="slide">
        <component :is="Component" :data="selectedSinger"></component>
      </transition>
    </router-view>
  </div>
</template>

<script>
import { getSingerList } from '../service/singer';
import indexList from '@/components/base/index-list/index-list.vue';
import { SINGER_KEY } from '@/assets/js/constant.js';
export default {
  name: 'singer',
  components: {
    indexList
  },
  data() {
    return {
      data: [],
      selectedSinger: null
    };
  },
  async created() {
    const result = await getSingerList();
    this.data = result.singers;
  },
  methods: {
    selectSinger(singer) {
      console.log(singer, 999);
      this.selectedSinger = singer;
      this.cacheSinger(singer);
      this.$router.push({
        path: `/singer/${singer.mid}`
      });
    },
    // 本地缓存
    cacheSinger(singer) {
      const singers = JSON.stringify(singer);
      sessionStorage.setItem(SINGER_KEY, singers);
    }
  }
};
</script>

<style lang="scss" scoped>
.singer {
  position: fixed;
  width: 100%;
  top: 88px;
  bottom: 0;
}
</style>
